import mitt from "mitt";

const emitter = mitt();

export const VueBus = emitter;

/**
 * @description: 获取图片信息
 * @author: 王琛
 * @Date: 2022-08-15 16:06:50
 * @param {*}
 * @return {*}
 */
export function getImage(name) {
    const path = "/src/assets/images" + name;
    const modules = import.meta.glob("/src/assets/images/**/*.{png,svg,jpg,jpeg}", {eager: true});
    if (modules[path]) return modules[path]["default"]
}

/**
 * @description: 获取静态资源
 * @author: 王琛
 * @Date: 2023-07-07 10:43:50
 * @param {*}
 * @return {*}
 */
export function getPublic(name) {
    const path = "../../../public/" + name;
    const modules = import.meta.glob("../../../public/**/*.{png,svg,jpg,jpeg}", {eager: true});
    if (modules[path]) return modules[path]["default"]
}

/**
 * @author: 王琛
 * @description: 生成UUID
 * @Date: 2021-11-12 17:07:37
 * @param {*}
 * @return {*}
 */
export function getUuid() {
    let s = [];
    let hexDigits = "0123456789abcdef";
    for (let i = 0; i < 36; i++) {
        s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
    }
    s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
    s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
    s[8] = s[13] = s[18] = s[23] = "-";

    let uuid = s.join("");
    return uuid;
}
